<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<title></title>
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<link href="../../assets/lib/layui/css/layui.css" rel="stylesheet" />
	<link href="../../assets/lib/winui/css/winui.css" rel="stylesheet" />
	<style type="text/css">
		.ui-page {
			background: white;
		}

		.ui-header {
			background-color: #5693C0 ! important;
			text-shadow: 0 1px 0 #3D586C ! important;
			padding-bottom: 5px;
		}

		.ui-content {
			padding: 0px 1em;
		}

		.ui-footer {
			color: #3D586C ! important;
			background: none ! important;
		}

		.ui-header,
		.ui-footer {
			border: none ! important;
		}

		.starRating {
			font-size: 26px;
		}

		.starRating .fa {
			cursor: pointer;
		}

		.starRating .fa-star {
			color: #3388CC;
		}

		.subbtn {
			opacity: 1 ! important;
			color: white;
		}

		.quTitleNum {
			/* position: absolute; */

		}

		.quTitleText {
			/* text-indent: 2em; */

		}

		#dwSurveyNote {
			padding-top: 0px;
		}

		.m_quOrderByUi {
			margin: 5px 0 5px 0;
			padding: 0;
			border: 1px solid #d5d5d5;
			border-radius: 3px;
		}

		.m_quOrderByUi li {
			border-color: #fff;
			font-size: 16px;
			min-height: 41px;
			position: relative;
			padding-right: 45px !important;
			border-bottom: 1px solid #EBEBEB !important;
		}

		.m_orderby_num {
			position: absolute;
			right: 10px;
			top: 55%;
			margin-top: -15px;
			min-width: 26px;
			height: 26px;
			background: #85C8FF;
			color: #fff;
			text-align: center;
			line-height: 26px;
			border-radius: 15px;
			z-index: 100;
			display: none;
		}

		.m_orderby_sel {
			position: absolute;
			top: 0px;
			left: 0px;
			width: 100%;
			height: 100%;
			opacity: 0;
			font-size: 30px;
			z-index: 9999;
			background-color: rgb(248, 248, 248);
			border: 1px solid rgb(166, 166, 166);
			border-image-source: initial;
			border-image-slice: initial;
			border-image-width: initial;
			border-image-outset: initial;
			border-image-repeat: initial;
			display: inline-block;
		}

		#wrap {
			overflow-x: hidden;
			margin: 0px 5px;
		}

		#dwSurveyName {
			width: auto;
		}

		#dwSurveyNoteEdit {
			width: auto;
			padding-right: 10px;
		}

		.surveyQuItem .surveyQuItemContent {
			width: auto;
		}

		.surveyQuItem .surveyQuItemContent .quCoTitle .quCoTitleEdit {
			width: auto;
		}

		table.quCoChenTable {
			width: auto;
		}

		table.quCoChenTable tr td {
			min-width: 80px;
		}

		@media screen and (max-width: 960px) {

			/* 手机端CSS代码 */
			#dw_body_content {
				width: 100%;
			}
		}

		@media screen and (min-width: 960px) {

			/* 电脑端CSS代码 */
			#dw_body_content {
				width: 60%;
			}
		}
	</style>
</head>

<body style="background-color: RGB(232,233,235);">
	<div id="wrap">

	</div>
	<div class="footer-copyright footer-pb" style="color: gray;padding-bottom: 5px;">
		源码地址:
		<a href="https://gitee.com/doc_wei01_admin/skyeye" style="text-decoration: none;color: gray;">skyeye</a>&nbsp;
	</div>

	<!-- 1单选题radio -->
	<script type="text/x-handlebars-template" id="radioTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent">
						<div class="quCoTitle">
							<div class="quCoNum">{{showQuestionIndex quType}}、</div>
							<div class="quCoTitleEdit" >{{quTitle}}</div>
						</div>
						<div class="quCoItem">
						{{#if hv}}
							{{#compare1 hv '3'}}
								<table class='tableQuColItem'>
									{{#each radioTd}}
										<tr>
											{{#cellCount001 cellCount}}{{/cellCount001}}
										</tr>
									{{/each}}
									<tr>
								</table>
							{{else}}
							{{#if hv}}
							{{#compare1 hv '1'}}
								<ul class="transverse">
									{{#each radioTd}}
										<li class="quCoItemUlLi">
											<div class="dwQuOptionItemContent">
												<label class="dwRedioStyle dwQuInputLabel" ></label>
												<input type="radio" name="qu_{{quType}}_{{quId}}" value="{{id}}" >
												<label class="quCoOptionEdit quCoOptionPadding">{{optionName}}</label>
												<input type='text' class='inputSytle_1' style="width:200px;padding:5px;{{#compare2 isNote 0}}{{/compare2}}" name="text_qu_{{quType}}_{{quId}}_{{id}}" />
											</div>
										</li>
									{{/each}}
								</ul>
							{{else}}
								<ul>
									{{#each radioTd}}
										<li class="quCoItemUlLi">
											<div class="dwQuOptionItemContent">
												<label class="dwRedioStyle dwQuInputLabel" ></label>
												<input type="radio" name="qu_{{quType}}_{{quId}}" value="{{id}}" >
												<label class="quCoOptionEdit quCoOptionPadding">{{optionName}}</label>
												<input type='text' class='inputSytle_1' style="width:200px;padding:5px;{{#compare2 isNote 0}}{{/compare2}}" name="text_qu_{{quType}}_{{quId}}_{{id}}" />
											</div>
										</li>
									{{/each}}
								</ul>
							{{/compare1}}
							{{/if}}
						{{/compare1}}
						{{/if}}
						</div>
					</div>
				</div>
			</script>

	<!-- 2多选题checkbox -->
	<script type="text/x-handlebars-template" id="checkBoxTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent">
						<div class="quCoTitle">
							<div class="quCoNum">{{showQuestionIndex quType}}、</div>
							<div class="quCoTitleEdit" >{{quTitle}}</div>
						</div>
						<div class="quCoItem">
							{{#if hv}}
							{{#compare1 hv '3'}}
									<table class='tableQuColItem'>
										{{#each checkboxTd}}
											<tr>
												{{#cellCount002 cellCount}}{{/cellCount002}}
											</tr>
										{{/each}}
									</table>
								{{else}}
									{{#if hv}}
									{{#compare1 hv '1'}}
											<ul class="transverse">
												{{#each checkboxTd}}
													<li class="quCoItemUlLi">
														<div class="dwQuOptionItemContent">
															<label class="dwCheckboxStyle dwQuInputLabel" ></label>
															<input type="checkbox" name="tag_qu_{{quType}}_{{quId}}_{{id}}" value="{{id}}" class="custom-radio">
															<label class="quCoOptionEdit quCoOptionPadding">{{optionName}}</label>
															<input type='text' class='inputSytle_1' style="width:200px;padding:5px;{{#compare2 isNote 0}}{{/compare2}}" name="text_tag_qu_{{quType}}_{{quId}}_{{id}}" />
														</div>
													</li>
												{{/each}}
											</ul>
										{{else}}
											<ul>
												{{#each checkboxTd}}
													<li class="quCoItemUlLi">
														<div class="dwQuOptionItemContent">
															<label class="dwCheckboxStyle dwQuInputLabel" ></label>
															<input type="checkbox" name="tag_qu_{{quType}}_{{quId}}" value="{{id}}" class="custom-radio">
															<label class="quCoOptionEdit quCoOptionPadding">{{optionName}}</label>
															<input type='text' class='inputSytle_1' style="width:200px;padding:5px;{{#compare2 isNote 0}}{{/compare2}}" name="text_tag_qu_{{quType}}_{{quId}}_{{id}}" />
														</div>
													</li>
												{{/each}}
											</ul>
									{{/compare1}}
									{{/if}}
							{{/compare1}}
							{{/if}}
						</div>
					</div>
				</div>
			</script>

	<!-- 3填空题fillblank -->
	<script type="text/x-handlebars-template" id="fillblankTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent">
						<div class="quCoTitle">
							<div class="quCoNum">{{showQuestionIndex quType}}、</div>
							<div class="quCoTitleEdit" >{{quTitle}}</div>
						</div>
						<div class="quCoItem"><ul>
							<li class="quCoItemUlLi">
								<div class="quFillblankItem">
									{{#if answerInputRow}}
										{{#compare1 checkType '8'}}
												<input type="text" name="qu_{{quType}}_{{id}}" style="width: 300px;padding: 6px 10px 5px;border: 1px solid #83ABCB;outline: none;" class="fillblankInput Wdate"/>
											{{else}}
												{{#compare1 answerInputRow '1'}}
														<input type="text" name="qu_{{quType}}_{{id}}" style="width:{{answerInputWidth}}px;" class="inputSytle_1 fillblankInput" >
													{{else}}
														<textarea name="qu_{{quType}}_{{id}}" rows="{{answerInputRow}}" style="width:{{answerInputWidth}}px;"class="inputSytle_2 fillblankInput" ></textarea>
												{{/compare1}}
										{{/compare1}}
									{{/if}}
									<div class="dwComEditMenuBtn" ></div>
								</div>
							</li>
						</ul>
						</div>
					</div>
				</div>
			</script>

	<!-- 9排序题orderby -->
	<script type="text/x-handlebars-template" id="orderbyTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent">
						<div class="quCoTitle">
							<div class="quCoNum">{{showQuestionIndex quType}}、</div>
							<div class="quCoTitleEdit">{{quTitle}}</div>
						</div>
						<div class="quCoItem quOrderByCoItem">
							<div class="quOrderByRight">
								<table class="quOrderByTable" style="padding:5px;">
									{{#each orderByTd}}
										<tr class="quOrderByTableTr">
											<td class="quOrderyTableTd">{{showIndex @index}}</td>
											<td class="quOrderTabConnect"></td>
										</tr>
									{{/each}}
								</table>
							</div>
							<div  class="quOrderByLeft">
								<ul class="quOrderByLeftUl">
									{{#each orderByTd}}
										<li class="quCoItemUlLi">
											<label class="quCoOptionEdit">{{optionName}}
												<input name="item_qu_{{quType}}_{{quId}}_{{id}}" value="1" type="hidden" class="quOrderItemHidInput">
											</label>
										</li>
									{{/each}}
								</ul>
							</div>
							<div style="clear: both;"></div>
						</div>
					</div>
				</div>
			</script>

	<!-- 16分页pagetag -->
	<script type="text/x-handlebars-template" id="pagetagTemplate">
				<div class="surveyQuItem">
					<div class="pageBorderTop nohover"></div>
					<div class="surveyQuItemContent" style="padding-top: 12px;height: 30px;min-height: 30px;">
						<a href="#" class="sbtn24 sbtn24_0 nextPage_a" >下一页</a>&nbsp;&nbsp;
						{{#if pageNo}}
						{{#compare7 pageNo}}
							<a href="#" class="sbtn24 sbtn24_1 prevPage_a">上一页</a>
							{{else}}
						{{/compare7}}
						{{/if}}
						<input type="hidden" name="nextPageNo" value="{{pageNo}}">
					</div>
				</div>
			</script>

	<!-- 17段落paragraph -->
	<script type="text/x-handlebars-template" id="paragraphTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent" style="min-height: 35px;">
						<div class="quCoTitle" style="background: rgb(243, 247, 247);">
							<div class="quCoTitleEdit" style="padding-left: 15px;">{{quTitle}}</div>
						</div>
					</div>
				</div>
			</script>

	<!-- 4多项填空题multi-fillblank -->
	<script type="text/x-handlebars-template" id="multiFillblankTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent">
						<div class="quCoTitle">
							<div class="quCoNum">{{showQuestionIndex quType}}、</div>
							<div class="quCoTitleEdit">{{quTitle}}</div>
						</div>
						<div class="quCoItem">
							<table class="mFillblankTable">
								{{#each multifillblankTd}}
									<tr class="mFillblankTableTr">
										<td align="right" class="mFillblankTableEditTd">
											<label class="quCoOptionEdit">{{optionName}}</label>
											<input class="dwMFillblankOptionId" type="hidden" value="{{id}}" disabled="disabled">
											<input type="hidden" name="answerTag" value="0">
										</td>
										<td>
											<input name="text_qu_{{quType}}_{{quId}}_{{id}}" type="text" style="width:200px;padding:5px;" class="inputSytle_1 dwMFillblankInput">
										</td>
									</tr>
								{{/each}}
							</table>
						</div>
					</div>
				</div>
			</script>

	<!-- 11矩阵单选题chen-radio -->
	<script type="text/x-handlebars-template" id="chenRadioTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent">
						<div class="quCoTitle">
							<div class="quCoNum">{{showQuestionIndex quType}}、</div>
							<div class="quCoTitleEdit">{{quTitle}}</div>
						</div>
						<div class="quCoItem">
							<div class="quCoItemLeftChenTableDiv">
								<table class="quCoChenTable" >
									<tr><td></td>
										{{#each columnTd}}
											<td class="quChenColumnTd">
												<label class="quCoOptionEdit">{{optionName}}</label>
											</td>
										{{/each}}
									</tr>
									{{#each rowTd}}
										<tr class="dwQuCoChenRowTr">
											<td class="quChenRowTd"><label class="quCoOptionEdit">{{optionName}}</label>
												<input type="hidden" class="answerTag" value="0" >
											</td>
											{{#each ../columnTd}}
												<td>
													<div class="dwQuOptionItemContent">
														<label class="dwRedioStyle dwQuInputLabel" ></label>
														<input type="hidden" class="dwChenInputTemp" disabled="disabled" value="{{../id}}:{{id}}">
														<input name="item_qu_{{quType}}_{{quId}}_{{../id}}" value="{{id}}" type="radio">
													</div>
												</td>
											{{/each}}
										</tr>
									{{/each}}
								</table>
							</div>
						</div>
						<div style="clear: both;"></div>
					</div>
				</div>
			</script>

	<!-- 13矩阵多选题chen-checkbox -->
	<script type="text/x-handlebars-template" id="chenCheckboxTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent">
						<div class="quCoTitle">
							<div class="quCoNum">{{showQuestionIndex quType}}、</div>
							<div class="quCoTitleEdit" >{{quTitle}}</div>
						</div>
						<div class="quCoItem">
							<div class="quCoItemLeftChenTableDiv">
								<table class="quCoChenTable" >
									<tr><td></td>
										{{#each columnTd}}
											<td class="quChenColumnTd">
												<label class="quCoOptionEdit">{{optionName}}</label>
											</td>
										{{/each}}
									</tr>
									{{#each rowTd}}
										<tr class="dwQuCoChenRowTr">
											<td class="quChenRowTd"><label class="quCoOptionEdit">{{optionName}}</label>
												<input type="hidden" name="item_qu_{{quType}}_{{quId}}_{{id}}" value="ck_item_qu_{{quType}}_{{quId}}_{{id}}_" />
												<input type="hidden" class="answerTag" value="0" >
											</td>
											{{#each ../columnTd}}
												<td>
													<div class="dwQuOptionItemContent">
														<label class="dwCheckboxStyle dwQuInputLabel" ></label>
														<input type="hidden" class="dwChenInputTemp" disabled="disabled" value="{{../id}}:{{id}}">
														<input name="ck_item_qu_{{quType}}_{{quId}}_{{../id}}_{{id}}" value="{{id}}" type="checkbox">
													</div>
												</td>
											{{/each}}
										</tr>
									{{/each}}
								</table>
							</div>
						</div>
						<div style="clear: both;"></div>
					</div>
				</div>
			</script>

	<!-- 12矩阵填空题chen-fbk -->
	<script type="text/x-handlebars-template" id="chenFbkTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent">
						<div class="quCoTitle">
							<div class="quCoNum">{{showQuestionIndex quType}}、</div>
							<div class="quCoTitleEdit" >{{quTitle}}</div>
						</div>
						<div class="quCoItem">
							<div class="quCoItemLeftChenTableDiv">
								<table class="quCoChenTable" >
									<tr><td></td>
										{{#each columnTd}}
											<td class="quChenColumnTd"><label class="quCoOptionEdit">{{optionName}}</label>
											</td>
										{{/each}}
									</tr>
									{{#each rowTd}}
										<tr class="dwQuCoChenRowTr">
											<td class="quChenRowTd"><label class="quCoOptionEdit">{{optionName}}</label>
												<input type="hidden" name="item_qu_{{quType}}_{{quId}}_{{id}}" value="fbk_item_qu_{{quType}}_{{quId}}_{{id}}_" />
											</td>
											{{#each ../columnTd}}
												<td>
													<div class="dwQuChenFbkOptionItemContent">
														<input type="hidden" class="dwChenInputTemp" disabled="disabled" value="{{../id}}:{{id}}">
														<input name="fbk_item_qu_{{quType}}_{{quId}}_{{../id}}_{{id}}" class="inputSytle_1 dwChenMFillblankInput" type="text">
														<input type="hidden" class="answerTag" value="0" >
													</div>
												</td>
											{{/each}}
										</tr>
									{{/each}}
								</table>
							</div>
						</div>
						<div style="clear: both;"></div>
					</div>
				</div>
			</script>

	<!-- 18矩阵评分题chen-score -->
	<script type="text/x-handlebars-template" id="chenScoreTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent">
						<div class="quCoTitle">
							<div class="quCoNum">{{showQuestionIndex quType}}、</div>
							<div class="quCoTitleEdit" >{{quTitle}}</div>
						</div>
						<div class="quCoItem">
							<div class="quCoItemLeftChenTableDiv">
								<table class="quCoChenTable" >
									<tr><td></td>
										{{#each columnTd}}
											<td class="quChenColumnTd"><label class="quCoOptionEdit">{{optionName}}</label>
											</td>
										{{/each}}
									</tr>
									{{#each rowTd}}
										<tr class="dwQuCoChenRowTr">
											<td class="quChenRowTd"><label class="quCoOptionEdit">{{optionName}}</label>
												<input type="hidden" name="item_qu_{{quType}}_{{quId}}_{{id}}" value="cs_item_qu_{{quType}}_{{quId}}_{{id}}_" />
											</td>
											{{#each ../columnTd}}
												<td>
													<div class="dwQuScoreOptionItemContent">
														<input type="hidden" class="dwChenInputTemp" disabled="disabled" value="{{../id}}:{{id}}">
														<select name="cs_item_qu_{{quType}}_{{quId}}_{{../id}}_{{id}}" class="quChenScoreSelect" >
															<option value="0">-评分-</option>
															{{#scoreNum001 5}}{{/scoreNum001}}
														</select>
														<input type="hidden" class="answerTag" value="0" >
													</div>
												</td>
											{{/each}}
										</tr>
									{{/each}}
								</table>
							</div>
						</div>
						<div style="clear: both;"></div>
					</div>
				</div>
			</script>

	<!-- 8评分题score -->
	<script type="text/x-handlebars-template" id="scoreTemplate">
				<div class="surveyQuItem">
					<div class="surveyQuItemContent">
						<div class="quCoTitle">
							<div class="quCoNum">{{showQuestionIndex quType}}、</div>
							<div class="quCoTitleEdit" >{{quTitle}}</div>
						</div>
						<div class="quCoItem">
							<table class="quCoItemTable" cellpadding="0" cellspacing="0">
								{{#each scoreTd}}
									<tr class="quScoreOptionTr">
										<td class="quCoItemTableTd quOptionEditTd">
											<label class="quCoOptionEdit">{{optionName}}</label>
											<input class="dwScoreOptionId" value="{{id}}" disabled="disabled" type="hidden"/>
											<input type="hidden" class="answerTag" value="0" >
										</td>
										<td class="quCoItemTableTd">
											<table class="scoreNumTable">
												<tr>
													{{#showParamInt02 ../paramInt02}}{{/showParamInt02}}
												</tr>
											</table>
											<input name="item_qu_{{quType}}_{{quId}}_{{id}}" value="" type="hidden" class="scoreNumInput" >
										</td>
										<td class="quCoItemTableTd">分</td>
									</tr>
								{{/each}}
							</table>
						</div>
					</div>
				</div>
			</script>

	<script src="../../assets/lib/layui/layui.js"></script>
	<script src="../../assets/lib/layui/custom.js"></script>
	<script type="text/javascript">
		var quIndex = 0;//问题序号
		var pageNum = 1;//模拟页码
		var nowPageNum = 1;//当前页码

		var ruleCode = "";//密码

		var bgAnDate = "";//答卷开始时间
		var hasCreatedAnswerRecord = false;
		var serveyInfo = {};//试卷信息
		var questions = [];//所有题目

		layui.config({
			base: basePath,
			version: skyeyeVersion
		}).extend({
			window: 'js/winui.window',
		}).define(['window', 'jquery', 'winui', 'validate'], function (exports) {
			winui.renderColor();
			layui.use(['form', 'jqueryUI'], function (form) {
				var index = parent.layer.getFrameIndex(window.name);
				var $ = layui.$,
					form = layui.form;
				bgAnDate = getFormatDate();

				AjaxPostUtil.request({
					url: sysMainMation.surveyBasePath + "takeExam", params: { id: getUrlParam("rowId") }, type: 'json', callback: function (json) {
						showGrid({
							id: "wrap",
								url: sysMainMation.surveyBasePath + "queryDwSurveyDirectoryMationByIdToHTML",
							params: { id: getUrlParam("rowId") },

							pagination: false,
							template: getFileContent('tpl/dwsurveydesign/surveyTemplate.tpl'),
							ajaxSendLoadBefore: function (hdb, json) {
								hdb.registerHelper("showQuestionIndex", function (v1, options) {
									if (v1 == '16' || v1 == '17') {
									} else {
										quIndex++;
										return quIndex;
									}
								});

								hdb.registerHelper("showIndex", function (v1, options) {
									return parseInt(v1) + 1;
								});

								hdb.registerHelper("showParamInt02", function (v1, options) {
									var str = "";
									for (var i = 1; i <= v1; i++) {
										str += "<td style='background-color: white;'>" + i + "</td>";
									}
									return str;
								});

								hdb.registerHelper('compare1', function (v1, v2, options) {
									if (v1 == v2) {
										return options.fn(this);
									} else {
										return options.inverse(this);
									}
								});

								hdb.registerHelper('showQuestion', function (v1, i, options) {
									switch (v1) {
										case 1://1单选题radio
											return new Handlebars.SafeString(getDataUseHandlebars($("#radioTemplate").html(), json.rows[i]));
											break;
										case 2://2多选题checkbox
											return new Handlebars.SafeString(getDataUseHandlebars($("#checkBoxTemplate").html(), json.rows[i]));
											break;
										case 3://3填空题fillblank
											return new Handlebars.SafeString(getDataUseHandlebars($("#fillblankTemplate").html(), json.rows[i]));
											break;
										case 4://4多项填空题multi-fillblank
											return new Handlebars.SafeString(getDataUseHandlebars($("#multiFillblankTemplate").html(), json.rows[i]));
											break;
										case 8://8评分题score
											return new Handlebars.SafeString(getDataUseHandlebars($("#scoreTemplate").html(), json.rows[i]));
											break;
										case 9://9排序题orderby
											return new Handlebars.SafeString(getDataUseHandlebars($("#orderbyTemplate").html(), json.rows[i]));
											break;
										case 11://11矩阵单选题chen-radio
											return new Handlebars.SafeString(getDataUseHandlebars($("#chenRadioTemplate").html(), json.rows[i]));
											break;
										case 12://12矩阵填空题chen-fbk
											return new Handlebars.SafeString(getDataUseHandlebars($("#chenFbkTemplate").html(), json.rows[i]));
											break;
										case 13://13矩阵多选题chen-checkbox
											return new Handlebars.SafeString(getDataUseHandlebars($("#chenCheckboxTemplate").html(), json.rows[i]));
											break;
										case 16://16分页pagetag
											return new Handlebars.SafeString(getDataUseHandlebars($("#pagetagTemplate").html(), json.rows[i]));
											break;
										case 17://17段落paragraph
											return new Handlebars.SafeString(getDataUseHandlebars($("#paragraphTemplate").html(), json.rows[i]));
											break;
										case 18://18矩阵评分题chen-score
											return new Handlebars.SafeString(getDataUseHandlebars($("#chenScoreTemplate").html(), json.rows[i]));
											break;
									}
								});

								hdb.registerHelper('compare2', function (v1, v2, options) {
									if (v1 == v2) {
										return 'display: none;';
									} else {
										return '';
									}
								});

								hdb.registerHelper('compare3', function (v1, v2, options) {
									if (v1 > v2) {
										return options.fn(this);
									} else {
										return options.inverse(this);
									}
								});

								hdb.registerHelper('compare4', function (v1, options) {
									if (v1 == nowPageNum) {
										return '';
									} else {
										return 'display: none;';
									}
								});

								hdb.registerHelper('compare5', function (v1, options) {
									if (v1 == '16') {
										if (pageNum == '1') {
											pageNum++;
											return '';
										} else {
											pageNum++;
										}
									}
									if (pageNum == '1') {
										return '';
									} else {
										return 'display: none;';
									}
								});

								hdb.registerHelper('compare6', function (v1, options) {
									return pageNum;
								});

								hdb.registerHelper('compare7', function (v1, options) {
									if (nowPageNum == '1') {
										return options.inverse(this);
									} else {
										return options.fn(this);
									}
								});

								hdb.registerHelper('compare8', function (v1, v2) {
									if (v1 == 3) {
										//填空题
										return '<input type="hidden" class="checkType" value="' + v2 + '">';
									}
									return "";
								});

								hdb.registerHelper('compare9', function (v1, v2, v3) {
									if (v1 == 8) {
										//评分题
										return '<input type="hidden" class="geLe" value="' + v2 + '">'
											+ '<input type="hidden" class="scoreNum" value="' + v3 + '">';
									}
									return "";
								});

								hdb.registerHelper('compare10', function (v1, v2) {
									if (v1 == 2) {
										//多选题
										return '<input type="hidden" name="qu_' + v1 + '_' + v2 + '" value="tag_qu_' + v1 + '_' + v2 + '_" />';
									} else if (v1 == 9 || v1 == 11 || v1 == 13 || v1 == 12 || v1 == 18 || v1 == 8) {
										//排序题，矩阵单选题，矩阵多选题，矩阵填空题，矩阵评分题，评分题
										return '<input type="hidden" name="qu_' + v1 + '_' + v2 + '" value="item_qu_' + v1 + '_' + v2 + '_" />';
									} else if (v1 == 4) {
										//多项填空题
										return '<input type="hidden" name="qu_' + v1 + '_' + v2 + '" value="text_qu_' + v1 + '_' + v2 + '_" />';
									}
									return "";
								});

								hdb.registerHelper("cellCount001", function (v1, options) {
									var str = "";
									var width = 600 / v1;
									for (var i = 1; i <= v1; i++) {
										str += '<td width="' + width + 'px">' +
											'<div class="dwQuOptionItemContent">' +
											'<label class="dwRedioStyle dwQuInputLabel" ></label>' +
											'<input type="radio" name="qu_{{quType}}_{{quId}}" value="{{id}}" >' +
											'<label style="width:' + (width - 10) + 'px;" class="editAble quCoOptionEdit quCoOptionPadding">{{optionName}}</label>' +
											'<input type="text" class="inputSytle_1" style="width:200px;padding:5px;{{#compare2 isNote 0}}{{/compare2}}" name="text_qu_{{quType}}_{{quId}}_{{id}}" />' +
											'</div>' +
											'</td>';
									}
									str += '<div class="emptyTd"></div>';
									return str;
								});

								hdb.registerHelper("cellCount002", function (v1, options) {
									var str = "";
									var width = 600 / v1;
									for (var i = 1; i <= v1; i++) {
										str += '<td width="' + width + 'px">' +
											'<div class="dwQuOptionItemContent">' +
											'<label class="dwCheckboxStyle dwQuInputLabel" ></label>' +
											'<input type="checkbox" name="tag_qu_{{quType}}_{{quId}}" value="{{id}}" >' +
											'<label style="width:' + (width - 10) + 'px;" class="editAble quCoOptionEdit quCoOptionPadding">{{optionName}}</label>' +
											'<input type="text" class="inputSytle_1" style="width:200px;padding:5px;{{#compare2 isNote 0}}{{/compare2}}" name="text_tag_qu_{{quType}}_{{quId}}_{{id}}" />' +
											'</div>' +
											'</td>';
									}
									str += '<div class="emptyTd"></div>';
									return str;
								});

								hdb.registerHelper("scoreNum001", function (v1, options) {
									var str = "";
									for (var i = 1; i <= v1; i++) {
										str += '<option value="' + i + '">' + i + '分</option>';
									}
									return str;
								});
							},
							ajaxSendAfter: function (json) {
								loadModel();
							}
						});

						// ********************************************************************************************************
						AjaxPostUtil.request({
							url: sysMainMation.surveyBasePath + "querySurveyAnswerById",
							params: { id: getUrlParam("rowId") },
							type: 'json',
							callback: function (json) {
								console.log("querySurveyAnswerById返回数据：", json)
								if (json.id) {
									console.log("有答题记录")
									hasCreatedAnswerRecord = true;
									answerRecordId = json.bean.id;
									// 保存回答信息以便后续使用
									// var answerData = json.bean;
									// // 创建答题记录
									// var answerRecordId = createAnswerRecord(answerData);
									// console.log("创建的答题记录 ID：", answerRecordId);
									// 2. 然后获取问卷基本信息

								} else {
									console.log("没有答题记录")
									// 如果获取回答信息失败，仍然加载问卷
									initPageJson();
								}
							},
							errorCallback: function () {
								// 出错时仍然加载问卷
								initPageJson();
							}
						});

						//获取问卷信息
						function initPageJson(callback) {
							var params = {
								id: getUrlParam("rowId"),
								surveyId: getUrlParam("rowId"), // 假设rowId是当前试卷ID
								dataSource: 0,
								bgAnDate: bgAnDate,
								handleState: "0",
							};

							AjaxPostUtil.request({
								url: sysMainMation.surveyBasePath + "queryDirectoryById",//根据id获取问卷信息
								pagination: false,
								params: params,
								type: 'json',
								callback: function (json) {
									serveyInfo.value = json.bean || {}
									questions.value = json.rows || []

									if (!hasCreatedAnswerRecord.value) {
										createAnswerRecord()
									}

									// json.total = 1;
									// $.each(json.rows, function (i, item) {
									// 	item.saveTag = 1;
									// });
									// loadPageJson = json;
									// if (typeof (callback) == "function") {
									// 	callback();
									// } else {
									// 	initPage();
									// }
								}
							});
						}

						// 创建试卷回答信息
					function createAnswerRecord() {
						systemCommonUtil.getSysCurrentLoginUserMation(function (data) {
							currentUserMation = data.bean;
						});

							console.log("创建答题记录")
							// // 获取当前用户信息（假设已有相关方法）
							// var currentUser = getCurrentUser();
						var quNum = $(".li_surveyQuItemBody").length - 1;
						// 准备请求参数
							var params = {
								surveyId: getUrlParam("rowId"), // 假设rowId是当前试卷ID
								dataSource: 0,
								bgAnDate: bgAnDate,
								handleState: 0,
								// isComplete: 0,//是否完成 1完成 0未完成
								// isEffective: 1,//是否是有效数据 1有效 0无效
								// totalTime: 0,
								createId: currentUserMation.id,
								// state: 1,//教师是否阅卷 1.否 2.是
								quNum:quNum,//题数
								// completeItemNum:0,//回答的题项目数 ---- 表示有些题下面会有多重回答
								// completeNum:1//回答的题数

							};
							console.log("params:", params)

							// 发送AJAX请求
							AjaxPostUtil.request({
								url: sysMainMation.surveyBasePath + "writeDwSurveyAnswer",
								type: 'json',
								params: params,
								callback: function (json) {

									if (!hasCreatedAnswerRecord) {
										hasCreatedAnswerRecord = true;
										answerRecordId = json.bean.id;
										console.log("答题记录创建成功，ID：", answerRecordId);

										// 可以在这里执行创建成功后的回调
										if (typeof callback == 'function') {
											callback(true);
										}
									}  else {
										layer.msg('创建失败: ' + (json.returnMessage || '未知错误'), { icon: 2 });
										if (typeof callback == 'function') {
											callback(false);
										}
									}
								},
								error: function (xhr, status, error) {
									layer.msg('请求出错: ' + error, { icon: 2 });
									if (typeof callback == 'function') {
										callback(false);
									}
								}
							});
						}

						// ************************************************************************************************
						ruleCode = json.bean.ruleCode;
						if (json.bean.rule == '3') {
							_openNewWindows({
								url: "../../tpl/dwsurveydesign/dwsurveydesignrulecode.html",
								title: "问卷密钥",
								area: ['300px', '200px'],
								closeBtn: 0,
								pageId: "dwsurveydesignrulecode",
								callBack: function (refreshCode) {
								}
							});
						}
					}
				});

				//获取url中的参数
				function getUrlParam(name) {
					var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
					var r = window.location.search.substr(1).match(reg); //匹配目标参数
					if (r != null) return unescape(r[2]);
					return null; //返回参数值
				}

				//分页设置 nextPage_a prevPage_a
				$("body").on("click", ".nextPage_a", function (e) {
					if (validateForms()) {
						var thParent = $(this).parent();
						nowPageNum = nowPageNum + 1;
						$(".li_surveyQuItemBody").hide();
						$(".surveyQu_" + nowPageNum).fadeIn("slow");
						$("html,body").animate({
							scrollTop: 10
						}, 500);
						return false;
					}
				});
				$("body").on("click", ".prevPage_a", function (e) {
					var thParent = $(this).parent();
					nowPageNum = nowPageNum - 1;
					$(".li_surveyQuItemBody").hide();
					$(".surveyQu_" + nowPageNum).fadeIn("slow");
					$(window).scrollTop(10);
					return false;
				});

				$.fn.serializeJson = function () {
					var serializeObj = {};
					var array = this.serializeArray();
					var str = this.serialize();
					$(array).each(function () {
						if (serializeObj[this.name]) {
							if ($.isArray(serializeObj[this.name])) {
								serializeObj[this.name].push(this.value);
							} else {
								serializeObj[this.name] = [
									serializeObj[this.name], this.value];
							}
						} else {
							serializeObj[this.name] = this.value;
						}
					});
					return serializeObj;
				};

				function loadModel() {
					var prevHost = $("#prevHost").val();
					//初始化弹出窗口参数
					var surveyStyleId = $("#surveyStyleId").val();
					if (surveyStyleId != "") {
						/** 背景样式 **/
						var showBodyBi = "${surveyStyle.showBodyBi}";
						var bodyBgColor = "${surveyStyle.bodyBgColor}";
						var bodyBgColorObj = $("input[name='bodyBgColor']");
						bodyBgColorObj.val(bodyBgColor);
						var bodyBCThemeParamObj = bodyBgColorObj.parents(".theme_param");
						bodyBCThemeParamObj.find(".color_box").css({
							"background-color": bodyBgColor
						});
						$("body").css({
							"background-color": bodyBgColor
						});

						var bodyBgImage = "${surveyStyle.bodyBgImage}";
						var bodyBgImageObj = $("input[name='bodyBgImage']");
						var bodyBIThemeParamObj = bodyBgImageObj.parents(".theme_param");
						bodyBgImageObj.val(bodyBgImage);
						bodyBIThemeParamObj.find(".previewImage").attr("src", prevHost + bodyBgImage);
						if (showBodyBi == 1) {
							$("body").css({
								"background-image": "url(" + prevHost + bodyBgImage + ")"
							});
							$("input[name='showBodyBi']").prop("checked", true);
						}

						/** 表头样式 **/
						var showSurveyHbgi = "${surveyStyle.showSurveyHbgi}";
						var surveyHeadBgColor = "${surveyStyle.surveyHeadBgColor}";
						var surveyHeadBgColorObj = $("input[name='surveyHeadBgColor']");
						var surveyHBCThemeParamObj = surveyHeadBgColorObj.parents(".theme_param");
						surveyHeadBgColorObj.val(surveyHeadBgColor);
						surveyHBCThemeParamObj.find(".color_box").css({
							"background-color": surveyHeadBgColor
						});
						$("#dwSurveyHeader").css({
							"background-color": surveyHeadBgColor
						});

						var surveyHeadBgImage = "${surveyStyle.surveyHeadBgImage}";
						var surveyHeadBgImageObj = $("input[name='surveyHeadBgImage']");
						var surveyHBIThemeParamObj = surveyHeadBgImageObj.parents(".theme_param");
						surveyHeadBgImageObj.val(surveyHeadBgImage);
						surveyHBIThemeParamObj.find(".previewImage").attr("src", prevHost + surveyHeadBgImage);
						if (showSurveyHbgi == 1) {
							$("#dwSurveyHeader").css({
								"background-image": "url(" + prevHost + surveyHeadBgImage + ")"
							});
							$("input[name='showSurveyHbgi']").prop("checked", true);
						}

						var surveyHeadPaddingTop = "${surveyStyle.surveyHeadPaddingTop}";
						var surveyHeadPaddingBottom = "${surveyStyle.surveyHeadPaddingBottom}";
						$("#dwSurveyHeader").css({
							"padding-top": surveyHeadPaddingTop + "px"
						});
						$("#dwSurveyHeader").css({
							"padding-bottom": surveyHeadPaddingBottom + "px"
						});

						/** 内容中间样式 **/
						var showSurveyCbim = "${surveyStyle.showSurveyCbim}";
						var surveyContentBgColorMiddle = "${surveyStyle.surveyContentBgColorMiddle}";
						var surveyContentBgColorMiddleObj = $("input[name='surveyContentBgColorMiddle']");
						var surveyCBCMThemeParamObj = surveyContentBgColorMiddleObj.parents(".theme_param");
						surveyContentBgColorMiddleObj.val(surveyContentBgColorMiddle);
						surveyCBCMThemeParamObj.find(".color_box").css({
							"background-color": surveyContentBgColorMiddle
						});;
						$("#dwSurveyQuContentBg").css({
							"background-color": surveyContentBgColorMiddle
						});

						var surveyContentBgImageMiddle = "${surveyStyle.surveyContentBgImageMiddle}";
						var surveyContentBgImageMiddleObj = $("input[name='surveyContentBgImageMiddle']");
						var surveyCBIMThemeParamObj = surveyContentBgImageMiddleObj.parents(".theme_param");
						surveyContentBgImageMiddleObj.val(surveyContentBgImageMiddle);
						surveyCBIMThemeParamObj.find(".previewImage").attr("src", prevHost + surveyContentBgImageMiddle);
						if (showSurveyCbim == 1) {
							$("#dwSurveyQuContentBg").css({
								"background-image": "url(" + prevHost + surveyContentBgImageMiddle + ")"
							});
							$("input[name='showSurveyCbim']").prop("checked", true);
						}

						/** 文本样式 **/
						var questionTitleTextColor = "${surveyStyle.questionTitleTextColor}";
						var questionTitleTextColorObj = $("input[name='questionTitleTextColor']");
						var questionTTCThemeParamObj = questionTitleTextColorObj.parents(".theme_param");
						questionTitleTextColorObj.val(questionTitleTextColor);
						questionTTCThemeParamObj.find(".color_box").css({
							"background-color": questionTitleTextColor
						});
						$(".quCoTitle").css({
							"color": questionTitleTextColor
						});

						var questionOptionTextColor = "${surveyStyle.questionOptionTextColor}";
						var questionOptionTextColorObj = $("input[name='questionOptionTextColor']");
						var questionOTCThemeParamObj = questionOptionTextColorObj.parents(".theme_param");
						questionOptionTextColorObj.val(questionOptionTextColor);
						questionOTCThemeParamObj.find(".color_box").css({
							"background-color": questionOptionTextColor
						});
						$(".quCoOptionEdit").css({
							"color": questionOptionTextColor
						});

						var surveyTitleTextColor = "${surveyStyle.surveyTitleTextColor}";
						var surveyTitleTextColorObj = $("input[name='surveyTitleTextColor']");
						var surveyTTCThemeParamObj = surveyTitleTextColorObj.parents(".theme_param");
						surveyTitleTextColorObj.val(surveyTitleTextColor);
						surveyTTCThemeParamObj.find(".color_box").css({
							"background-color": surveyTitleTextColor
						});
						$("#dwSurveyTitle").css({
							"color": surveyTitleTextColor
						});

						var surveyNoteTextColor = "${surveyStyle.surveyNoteTextColor}";
						var surveyNoteTextColorObj = $("input[name='surveyNoteTextColor']");
						var surveyNTCThemeParamObj = surveyNoteTextColorObj.parents(".theme_param");
						surveyNoteTextColorObj.val(surveyNoteTextColor);
						surveyNTCThemeParamObj.find(".color_box").css({
							"background-color": surveyNoteTextColor
						});
						$("#dwSurveyNoteEdit").css({
							"color": surveyNoteTextColor
						});

						var surveyBtnBgColor = "${surveyStyle.surveyBtnBgColor}";
						if (surveyBtnBgColor !== "") {
							$("#dw_body_content .sbtn24,.progressbarDiv .ui-progressbar-value").css({
								"background-color": surveyBtnBgColor
							});
							$(".progressbarDiv").css({
								"border-color": surveyBtnBgColor
							});
							$(".progress-label ").css({
								"color": surveyBtnBgColor
							});
							var surveyBtnBgColorObj = $("input[name='surveyBtnBgColor']");
							surveyBtnBgColorObj.val(surveyBtnBgColor);
							var btnBcThemeParamObj = surveyBtnBgColorObj.parents(".theme_param");
							btnBcThemeParamObj.find(".color_box").css({
								"background-color": surveyBtnBgColor
							});
						}

						//显示序号及进度条
						var showTiNum = "${surveyStyle.showTiNum}";
						var showProgressbar = "${surveyStyle.showProgressbar}";
						if (showTiNum == 0) {
							$(".quCoNum").hide();
						}
						if (showProgressbar == 0) {
							$("#resultProgressRoot").hide();
						}

						//表头文本显示
						var showSurTitle = "${surveyStyle.showSurTitle}";
						var showSurNote = "${surveyStyle.showSurNote}";
						if (showSurTitle == 0) {
							$("#dwSurveyTitle").hide();
						}
						if (showSurNote == 0) {
							$("#dwSurveyNote").hide();
						}
					}

					bindScoreNumTdHover();
					//排序题
					bindQuOrderBySorts();

					/******************************处理题目逻辑设置 **************************************/
					//初始化 处理默认逻辑跳转为显示，则先隐藏元素
					var quLogics = $("#dwSurveyQuContent .quLogicItem");
					$.each(quLogics, function () {
						var loginItem = $(this);
						var cgQuItemId = loginItem.find(".cgQuItemId").val();
						var skQuId = loginItem.find(".skQuId").val();
						var logicId = loginItem.find(".logicId").val();
						var logicType = loginItem.find(".logicType").val();
						if (logicType === "2") {
							//逻辑类型为"显示"2  则初始化为隐藏
							var hidQuItemBody = $(".quId[value='" + skQuId + "']").parents(".li_surveyQuItemBody");
							hidQuItemBody.hide();
							hidQuItemBody.addClass("hidFor" + logicId);
							hidQuItemBody.find(".answerTag").attr("disabled", true);
						}
					});

					//填空题
					$(".fillblankInput,.dwMFillblankInput").blur(function () {
						var thVal = $(this).val();
						var quItemBody = $(this).parents(".li_surveyQuItemBody");
						var quId = quItemBody.find(".quId").val();
						var quType = quItemBody.find(".quType").val();

						// 保存答案
						saveFillblankAnswer({
							id: getUrlParam("rowId"),
							quId: quId,
							quType: quType,
							answer: thVal,
							answerRecordId:answerRecordId
						});

						runlogic($(this));
						answerProgressbar($(this));
						validateCheck(quItemBody, false);
					});

					// 矩阵填空题
					$(".dwChenMFillblankInput").blur(function() {
						var thObj = $(this);
						var quItemBody = thObj.parents(".li_surveyQuItemBody");
						var dwChenInputTemp = thObj.parent().find(".dwChenInputTemp").val();
						var rowId = dwChenInputTemp.split(":")[0];
						var columnId = dwChenInputTemp.split(":")[1];
						var answer = thObj.val();

						// 收集所有填空答案
						var answers = [{
							rowId: rowId,
							columnId: columnId,
							answer: answer
						}];

						// 调用保存函数
						saveChenFbkAnswer({
							id: getUrlParam("rowId"), // 问卷ID
							quId: quItemBody.find(".quId").val(), // 题目ID
							answers: answers, // 答案数组
							answerRecordId: answerRecordId // 答卷ID（如果有）
						});

						// 更新进度条
						answerProgressbar(thObj);
						// 运行逻辑
						runlogic(thObj);
						validateCheck(quItemBody, false);
					});

					$(".quChenScoreSelect").change(function () {
						answerProgressbar($(this));
						validateCheck($(this).parents(".li_surveyQuItemBody"), false);
					});

					resetQuNum();

					$("#mobileTdId").click(function () {
						$(this).next().slideToggle();
						return false;
					});

					var bfbFloat = 0;
					$("#resultProgress").progressbar({
						value: bfbFloat,
						orientation: "vertical"
					});
				}

				$("body").on("click", ".submitSurvey", function (e) {
					console.log("点击提交")
					if (!validateForms()) {
						return false;
					}
					if (validateForms()) {
						var endAnDate = getFormatDate();
						var params = {
							surveyId: getUrlParam("rowId"),
							// id: answerRecordId,
							// bgAnDate: bgAnDate,
							// handleState: "0",
							// dataSource: "0",
							// endAnDate: endAnDate,

						};
						console.log("提交")
						console.log("params:",params)
						AjaxPostUtil.request({
							url: sysMainMation.surveyBasePath + "writeDwSurveyAnswer", params: params, type: 'json', callback: function (json) {
								$("#wrap").html('<span class="messageSpan">' + '答题完成，感谢您的参与。' + '</span>');
							}
						});
					}
					return false;
				});

				//评分题
				$("body").on("click", ".scoreNumTable tr td", function (e) {
					var quScoreOptionTr = $(this).parents(".quScoreOptionTr");
					var tdText = $(this).text();
					var quItemBody = $(this).parents(".li_surveyQuItemBody");
					var quId = quItemBody.find(".quId").val();
					quScoreOptionTr.find(".scoreNumTable tr td").css({
						"background": "white"
					});
					quScoreOptionTr.find(".scoreNumText").html($(this).text() + "&nbsp;分");

					$(this).prevAll().css({
						"background": ""
					});
					$(this).css({
						"background": ""
					});
					quScoreOptionTr.find(".scoreNumInput").val(tdText);

					// 调用保存函数
					saveScoreAnswer({
						id: getUrlParam("rowId"), // 问卷ID
						quId: quId, // 题目ID
						score: tdText, // 评分值
						answerRecordId: answerRecordId // 答卷ID（如果有）
					});

					runlogic($(this));
					answerProgressbar($(this));
					validateCheck($(this).parents(".li_surveyQuItemBody"), false);

				});

				function bindScoreNumTdHover() {
					$(".scoreNumTable tr td").hover(function () {
						var quScoreOptionTr = $(this).parents(".quScoreOptionTr");
						var scoreNumInput = quScoreOptionTr.find(".scoreNumInput").val();
						if (scoreNumInput == "") {
							$(this).prevAll().css({
								"background": ""
							});
							$(this).css({
								"background": ""
							});
							quScoreOptionTr.find(".scoreNumText").html($(this).text() + "&nbsp;分");
						}
					}, function () {
						var quScoreOptionTr = $(this).parents(".quScoreOptionTr");
						var scoreNumInput = quScoreOptionTr.find(".scoreNumInput").val();
						if (scoreNumInput == "") {
							$(this).prevAll().css({
								"background": "white"
							});
							$(this).css({
								"background": "white"
							});
							quScoreOptionTr.find(".scoreNumText").html("分");
						}
					});

					// 矩阵评分题评分选择框change事件
					$(".quChenScoreSelect").off("change").on("change", function() {
						var thObj = $(this);
						var quItemBody = thObj.parents(".li_surveyQuItemBody");
						var dwChenInputTemp = thObj.parent().find(".dwChenInputTemp").val();
						var rowId = dwChenInputTemp.split(":")[0];
						var columnId = dwChenInputTemp.split(":")[1];
						var score = thObj.val();

						// 调用保存函数
						saveChenScoreAnswer({
							id: getUrlParam("rowId"), // 问卷ID
							quId: quItemBody.find(".quId").val(), // 题目ID
							rowId: rowId, // 行ID
							columnId: columnId, // 列ID
							score: score, // 评分值
							answerRecordId: answerRecordId // 答卷ID（如果有）
						});

						// 更新进度条
						answerProgressbar(thObj);
						// 运行逻辑
						runlogic(thObj);
					});
				}

				function bindQuOrderBySorts() {
					var quOrderByCoItems = $(".quOrderByCoItem");
					$.each(quOrderByCoItems, function () {
						$(this).find(".quOrderByLeftUl li").sortable({
							zIndex: 1000,
							scroll: false,
							opacity: 0.8,
							placeholderType: false,
							connectWith: $(this).find(".quOrderByTable td"),
							helper: function (event, ui) {
								return "<label class='quOrderItemLabel'>" + $(this).text() + "</label>";
							},
							over: function (event, ui) {

							},
							start: function (event, ui) {

							},
							drag: function (event, ui) {

							},
							stop: function (event, ui) {
								$(".quOrderByTable td").css({
									"background": ""
								});
								answerProgressbar($(this));
								validateCheck($(this).parents(".li_surveyQuItemBody"), false);

								saveOrderAnswerOnChange($(this).parents(".li_surveyQuItemBody"));
							}
						});
						var sortObjTempHtml = null;
						$(this).find(".quOrderByTable td").sortable({
							zIndex: 1000,
							scroll: false,
							opacity: 0.9,
							placeholderType: true,
							placeholder: "qu-order-highlight",
							connectWith: $(this).find(".quOrderByTable td"),
							over: function (event, ui) {
								$(".quOrderByTable td").css({
									"background": ""
								});
								$(this).css({
									"background": "#FAEDC0"
								});
								var quOrderItemLabel = $(this).find("label.quOrderItemLabel");
								sortObjTempHtml = "";
								if (quOrderItemLabel[0]) {
									sortObjTempHtml = quOrderItemLabel.html();
								}
							},
							receive: function (event, ui) { //当一个已连接的sortable对象接收到另一个sortable对象的元素后触发此事件。
								//判断如果是从右边新移入的，但当前td中已经有了，就交换到右边去
								var uiSenderClass = ui.sender.attr("class");
								ui.sender.empty();
								if (uiSenderClass.indexOf("quCoItemUlLi") < 0) {
									if (sortObjTempHtml != "") {
										ui.sender.append("<label class='quOrderItemLabel'>" + sortObjTempHtml + "</label>");
									}
								} else {
									if (sortObjTempHtml != "") {
										ui.sender.append("<label class='editAble quCoOptionEdit'>" + sortObjTempHtml + "</label>");
									}
								}

								$(this).empty();
								ui.item.clone().appendTo($(this));
								var quCoOptionEdit = $(this).find(".quCoOptionEdit");
								if (quCoOptionEdit[0]) {
									quCoOptionEdit.removeClass();
									quCoOptionEdit.addClass("quOrderItemLabel");
								}
								$(".quOrderByTable td").css({
									"background": ""
								});
								//更新排序ID  quCoItem quOrderByTableTr
								var quOrderyByTrs = $(".quCoItem .quOrderByTableTr");
								$.each(quOrderyByTrs, function (i) {
									var quOrderItemHidInput = $(this).find(".quOrderItemHidInput");
									quOrderItemHidInput.val(i + 1);
								});
								saveOrderAnswerOnChange($(this).parents(".li_surveyQuItemBody"));
							},
							start: function (event, ui) {
								$(".quOrderByTable td").css({
									"background": ""
								});
								$(this).css({
									"background": "#FAEDC0"
								});
							},
							drag: function (event, ui) {
								$(".quOrderByTable td").css({
									"background": ""
								});
								$(this).css({
									"background": "#FAEDC0"
								});
							},
							stop: function (event, ui) {
								$(".quOrderByTable td").css({
									"background": ""
								});
							},
							out: function (event, ui) { },
							activate: function (event, ui) { }
						});
					});
				}
				function saveOrderAnswerOnChange(quItemBody) {
					// 获取题目信息
					var quId = quItemBody.find(".quId").val();
					var quType = quItemBody.find(".quType").val();

					// 获取排序后的选项
					var orderItems = [];
					quItemBody.find(".quOrderByTableTr").each(function(index) {
						var itemId = $(this).find(".quOrderItemHidInput").attr("name").split("_").pop();
						orderItems.push({
							id: itemId,
							order: index + 1
						});
					});

					// 调用保存函数
					saveOrderAnswer({
						id: getUrlParam("rowId"), // 问卷ID
						quId: quId, // 题目ID
						orderItems: orderItems, // 排序后的选项数组
						answerRecordId: answerRecordId // 答卷ID
					});
				}

				/**初始化表单骓证配置**/
				function validateForms() {
					var result = true;
					var surveyQuItemBodys = $(".li_surveyQuItemBody");
					var firstError = null;
					$.each(surveyQuItemBodys, function () {
						var quItemBody = $(this);
						if (!validateCheck(quItemBody, true)) {
							//定位到这题
							if (firstError == null) {
								firstError = quItemBody;
							}
							result = false;
						}
					});
					if (firstError != null) {
						$(window).scrollTop(firstError.offset().top);
					}
					if ($("#jcaptchaImgBody").is(":visible")) {
						var jcaptchaInput = $("input[name='jcaptchaInput']").val();
						if (jcaptchaInput === "") {
							$("#jcaptchaImgBody .errorItem").show();
							result = false;
						} else {
							$("#jcaptchaImgBody .errorItem").hide();
						}
					}
					return result;
				}

				function validateCheck(quItemBody, isSubForm) {
					var quTypeMap = {
						1: 'RADIO',
						2: 'CHECKBOX',
						3: 'FILLBLANK',
						4: 'MULTIFILLBLANK',
						8: 'SCORE',
						9: 'ORDERQU',
						11: 'CHENRADIO',
						12: 'CHENFBK',
						13: 'CHENCHECKBOX',
						16: 'PAGETAG',
						17: 'PARAGRAPH',
						18: 'CHENSCORE',
					};

					if (quItemBody.is(":visible")) {

						var quId = quItemBody.find(".quId").val();
						var quTypeNum = quItemBody.find(".quType").val(); // 获取数字类型的quType
						var quType = quTypeMap[quTypeNum] || quTypeNum; // 转换为映射的字符串或保持原值
						var isRequired = quItemBody.find(".isRequired").val();
						var validateStatus = false;

						if (isRequired === "0") {
							validateStatus = true;
							return true;
						}
						if (quType === "RADIO") {
							validateStatus = quItemBody.find("input[type='radio']:checked")[0];
						} else if (quType === "CHECKBOX") {
							validateStatus = quItemBody.find("input[type='checkbox']:checked")[0];
						} else if (quType === "FILLBLANK") {
							validateStatus = quItemBody.find(".fillblankInput").val() != "";
						} else if (quType === "ORDERQU") {
							validateStatus = !quItemBody.find(".quOrderByLeftUl label")[0];
						} else if (quType === "SCORE") {
							validateStatus = true;
							var quScoreOptionTrs = quItemBody.find(".quScoreOptionTr");
							$.each(quScoreOptionTrs, function () {
								var scoreNumInput = $(this).find(".scoreNumInput");
								if (scoreNumInput.val() === "") {
									validateStatus = false;
									return false;
								}
							});
						} else if (quType === "MULTIFILLBLANK") {
							validateStatus = true;
							var quScoreOptionTrs = quItemBody.find(".mFillblankTableTr");
							$.each(quScoreOptionTrs, function () {
								var scoreNumInput = $(this).find(".dwMFillblankInput");
								if (scoreNumInput.val() === "") {
									validateStatus = false;
									return false;
								}
							});
						} else if (quType === "CHENRADIO") {
							validateStatus = true;
							var quScoreOptionTrs = quItemBody.find(".dwQuCoChenRowTr");
							$.each(quScoreOptionTrs, function () {
								var tempInputs = $(this).find(".checked");
								if (!tempInputs[0]) {
									validateStatus = false;
									return false;
								}
							});
						} else if (quType === "CHENCHECKBOX") {
							validateStatus = true;
							var quScoreOptionTrs = quItemBody.find(".dwQuCoChenRowTr");
							$.each(quScoreOptionTrs, function () {
								var tempInputs = $(this).find("input[type='checkbox']:checked");
								if (!tempInputs[0]) {
									validateStatus = false;
									return false;
								}
							});
						} else if (quType === "CHENSCORE") {
							var quChenScores = quItemBody.find(".quChenScoreSelect");
							validateStatus = true;
							$.each(quChenScores, function () {
								var tempInputs = $(this);
								if (tempInputs.val() === "0") {
									validateStatus = false;
									return false;
								}
							});
						} else if (quType === "CHENFBK") {
							var dwCMFBKs = quItemBody.find(".dwChenMFillblankInput");
							validateStatus = true;
							$.each(dwCMFBKs, function () {
								var tempInputs = $(this);
								if (tempInputs.val() === "") {
									validateStatus = false;
									return false;
								}
							});
						} else if (quType === "submitSurveyBtn" || quType === "PARAGRAPH" || quType === "PAGETAG") {
							return true;
						}
					} else {
						validateStatus = true;
					}
					if (validateStatus) {
						quItemBody.find(".errorItem").remove();
					} else {
						if (isSubForm && !quItemBody.find(".errorItem")[0]) {
							var errorHtml = "<div class=\"errorItem\"><label for=\"\" class=\"error\">请检查题目答案，为必答项！</label></div>";
							quItemBody.find(".quCoItem").append(errorHtml);
						}
					}
					return validateStatus;
				}

				/** 单选与多选条件触发 自定义单选多选效果 操作结束后得调用逻辑判断 **/
				$("body").on("click", ".dwQuOptionItemContent", function (e) {
					var thObj = $(this);
					var quItemBody = thObj.parents(".li_surveyQuItemBody");
					var quType = quItemBody.find(".quType").val();

					var dwQuInputLabel = thObj.find(".dwQuInputLabel");

					if ("RADIO" === quType || '1' === quType) {
						//单选题
						var selectedOptionId = thObj.find("input[type='radio']").val();

						// 调用保存函数
						saveRadioAnswer({
							id: getUrlParam("rowId"),  // 问卷ID
							quId: quItemBody.find(".quId").val(),  // 题目ID
							answer: selectedOptionId,  // 选项ID
							answerRecordId: answerRecordId  // 答卷ID(如果有)
						});
						quItemBody.find(".dwQuInputLabel").removeClass("checked");
						quItemBody.find("input[type='radio']").prop("checked", false);
						dwQuInputLabel.addClass("checked");
						thObj.find("input[type='radio']").prop("checked", true);
						runlogic(thObj.find("input[type='radio']"));
					} else if ("CHECKBOX" === quType || '2' === quType) {
						//多选题
						var quInputLabelClass = dwQuInputLabel.attr("class");
						var selectedOptions = quItemBody.find("input[type='checkbox']:checked").map(function () {
							return $(this).val();
						}).get(); // 获取所有选中的选项ID数组

						// 调用保存函数
						saveCheckboxAnswer({
							id: getUrlParam("rowId"), // 问卷ID
							quId: quItemBody.find(".quId").val(), // 题目ID
							answers: selectedOptions, // 选中的答案数组
							answerRecordId: answerRecordId // 答卷ID（如果有）
						});

						if (quInputLabelClass.indexOf("checked") > 0) {
							dwQuInputLabel.removeClass("checked");
							thObj.find("input[type='checkbox']").prop("checked", false);
						} else {
							dwQuInputLabel.addClass("checked");
							thObj.find("input[type='checkbox']").prop("checked", true);
						}
						runlogic(thObj.find("input[type='checkbox']"));
					} else if ("CHENRADIO" === quType || '11' === quType) {
						//矩陈单选
						var chenRow = thObj.parents("tr");
						var rowId = chenRow.find(".dwChenInputTemp").val().split(":")[0]; // 获取行ID
						var columnId = thObj.find("input[type='radio']").val(); // 获取列ID

						// 调用保存函数
						saveChenRadioAnswer({
							id: getUrlParam("rowId"), // 问卷ID
							quId: quItemBody.find(".quId").val(), // 题目ID
							rowId: rowId, // 行ID
							columnId: columnId,// 列ID
							answerRecordId: answerRecordId // 答卷ID（如果有）
						});

						chenRow.find(".dwQuInputLabel").removeClass("checked");
						chenRow.find("input[type='radio']").prop("checked", false);
						dwQuInputLabel.addClass("checked");
						thObj.find("input[type='radio']").prop("checked", true);
						runlogic(thObj.find("input[type='radio']"));
					}


					else if ("CHENCHECKBOX" === quType || '13' === quType) {
						//矩陈多选
						var quInputLabelClass = dwQuInputLabel.attr("class");
						var selectedOptions = quItemBody.find("input[type='checkbox']:checked").map(function () {
							return $(this).val();
						}).get(); // 获取所有选中的选项ID数组

						// 获取行ID和列ID
						var rowId = thObj.parents("tr").find(".dwChenInputTemp").val().split(":")[0]; // 行ID
						var columnId = thObj.find("input[type='checkbox']").val(); // 列ID

						// 调用保存函数
						saveChenCheckboxAnswer({
							id: getUrlParam("rowId"), // 问卷ID
							quId: quItemBody.find(".quId").val(), // 题目ID
							rowId: rowId, // 行ID
							columnId: columnId, // 列ID
							answerRecordId: answerRecordId // 答卷ID（如果有）
						});

						if (quInputLabelClass.indexOf("checked") > 0) {
							dwQuInputLabel.removeClass("checked");
							thObj.find("input[type='checkbox']").prop("checked", false);
						} else {
							dwQuInputLabel.addClass("checked");
							thObj.find("input[type='checkbox']").prop("checked", true);
						}
						runlogic(thObj.find("input[type='checkbox']"));

					}
					answerProgressbar(thObj);
					validateCheck(quItemBody, false);
				});

				//只要触发事件
				function runlogic(thFormElementObj) {
					var quItemBody = thFormElementObj.parents(".li_surveyQuItemBody");
					var quLogicItems = quItemBody.find(".quLogicItem");
					if (quLogicItems[0]) {
						var quInputCase = quItemBody.find(".quInputCase");
						var quId = quInputCase.find(".quId").val();
						var quType = quInputCase.find(".quType").val();
						if (quType === "RADIO" || quType === "CHECKBOX" || quType === "SCORE" || quType === "MULTIFILLBLANK" || quType === "CHENRADIO" || quType === "CHENCHECKBOX" || quType === "CHENSCORE" || quType === "CHENFBK" || quType === '1' || quType === '2' || quType === '8' || quType === '4' || quType === '11' || quType === '13' || quType === '18' || quType === '12') {
							//判断是否选中
							var quLgoicItem = null;
							//遍历每个逻辑设置
							var quOptionItems = null;
							if (quType === "RADIO" || quType === "CHECKBOX" || quType === '1' || quType === '2') {
								quOptionItems = quItemBody.find(".dwQuOptionItemContent");
							} else if (quType === "SCORE" || quType === '8') {
								quOptionItems = quItemBody.find(".quScoreOptionTr");
							} else if (quType === "MULTIFILLBLANK" || quType === '4') {
								quOptionItems = quItemBody.find(".mFillblankTableTr");
							} else if (quType === "CHENRADIO" || quType === "CHENCHECKBOX" || quType === '11' || quType === '13') {
								quOptionItems = quItemBody.find(".dwQuOptionItemContent");
							} else if (quType === "CHENFBK" || quType === '12') {
								quOptionItems = quItemBody.find(".dwQuChenFbkOptionItemContent");
							}
							$.each(quLogicItems, function () {
								var loginItem = $(this);
								var cgQuItemId = loginItem.find(".cgQuItemId").val();
								var skQuId = loginItem.find(".skQuId").val();
								var logicId = loginItem.find(".logicId").val();
								var logicType = loginItem.find(".logicType").val();
								var geLe = null;
								var scoreNum = null;
								if (quType === "SCORE" || quType === '8') {
									geLe = loginItem.find(".geLe").val();
									scoreNum = loginItem.find(".scoreNum").val();
								}
								//过滤优先级
								var isbreak = false;
								$.each(quOptionItems, function () {
									var quCoItem = $(this);
									var quInput = null;
									var logicStatus = false;
									var curQuItemId = null;
									if (quType === "RADIO" || quType === '1') {
										quInput = quCoItem.find("input[type='radio']");
										logicStatus = quInput.prop("checked");
										curQuItemId = quInput.val();
									} else if (quType === "CHECKBOX" || quType === '2') {
										quInput = quCoItem.find("input[type='checkbox']");
										logicStatus = quInput.prop("checked");
										curQuItemId = quInput.val();
									} else if (quType === "SCORE" || quType === '8') {
										quInput = quCoItem.find(".dwScoreOptionId");
										var curScore = quCoItem.find(".scoreNumInput").val();
										if (curScore != "") {
											logicStatus = (geLe === "le" && curScore <= scoreNum) || (geLe === "ge" && curScore >= scoreNum);
										}
										curQuItemId = quInput.val();
									} else if (quType === "MULTIFILLBLANK" || quType === '4') {
										quInput = quCoItem.find(".dwMFillblankOptionId");
										logicStatus = quCoItem.find(".dwMFillblankInput").val() != "";
										curQuItemId = quInput.val();
									} else if (quType === "CHENRADIO" || quType === '11') {
										quInput = quCoItem.find("input[type='radio']");
										logicStatus = quInput.prop("checked");
										curQuItemId = quCoItem.find(".dwChenInputTemp").val();
									} else if (quType === "CHENCHECKBOX" || quType === '13') {
										quInput = quCoItem.find("input[type='checkbox']");
										logicStatus = quInput.prop("checked");
										curQuItemId = quCoItem.find(".dwChenInputTemp").val();
									} else if (quType === "CHENFBK" || quType === '12') {
										quInput = quCoItem.find(".dwChenMFillblankInput");
										logicStatus = quInput.val() != "";
										curQuItemId = quCoItem.find(".dwChenInputTemp").val();
									}
									if (curQuItemId === cgQuItemId) {
										if (logicType === "1") {
											//跳转
											if (logicStatus) {
												//逻辑选项被选中状态，激活状态
												skQuestion(quItemBody.next(), skQuId, logicId, function () {
													//重新编题号
												});
												if (skQuId === "1" || skQuId === "2") {
													isbreak = true;
												}
											} else {
												var hidQuItemBodys = $(".hidFor" + logicId);
												$(".hidFor" + logicId).removeClass("hidFor" + logicId);
												$.each(hidQuItemBodys, function () {
													var thQuItemBodyClass = $(this).attr("class");
													if (thQuItemBodyClass.indexOf("hidFor") < 0) {
														$(this).show();
														//回答标记与逻辑设置没有关系
														$(this).find(".answerTag").attr("disabled", false);
													}
												});
											}
										} else {
											//逻辑类型为"显示" quType=2
											if (logicStatus) {
												//逻辑选项被选中状态，激活状态  显示题
												var hidQuItemBodys = $(".hidFor" + logicId);
												$(".hidFor" + logicId).removeClass("hidFor" + logicId);
												$.each(hidQuItemBodys, function () {
													var thQuItemBodyClass = $(this).attr("class");
													if (thQuItemBodyClass.indexOf("hidFor") < 0) {
														$(this).show();
														$(this).find(".answerTag").attr("disabled", false);
													}
												});
											} else {
												//隐藏题
												var hidQuItemBody = $(".quId[value='" + skQuId + "']").parents(".li_surveyQuItemBody");
												hidQuItemBody.hide();
												hidQuItemBody.addClass("hidFor" + logicId);
												hidQuItemBody.find(".answerTag").attr("disabled", true);
											}
										}
										return false;
									}
								});
								if (isbreak) {
									return false;
								}
							});
						} else if (quType === "FILLBLANK" || quType == '3') {
							//遍历每个逻辑设置
							var quOptionItems = quItemBody.find(".dwQuOptionItemContent");
							var thVal = thFormElementObj.val();
							$.each(quLogicItems, function () {
								var loginItem = $(this);
								var cgQuItemId = loginItem.find(".cgQuItemId").val();
								var skQuId = loginItem.find(".skQuId").val();
								var logicId = loginItem.find(".logicId").val();
								var logicType = loginItem.find(".logicType").val();
								if (logicType === "1") {
									//跳转
									if (thVal != "") {
										//逻辑选项被选中状态，激活状态
										skQuestion(quItemBody.next(), skQuId, logicId, function () {
											//重新编题号
										});
										if (skQuId === "1" || skQuId === "2") {
											isbreak = true;
										}
									} else {
										//逻辑选项未被选中状态，未激活
										var hidQuItemBodys = $(".hidFor" + logicId);
										$(".hidFor" + logicId).removeClass("hidFor" + logicId);
										$.each(hidQuItemBodys, function () {
											var thQuItemBodyClass = $(this).attr("class");
											if (thQuItemBodyClass.indexOf("hidFor") < 0) {
												$(this).show();
												//回答标记与逻辑设置没有关系
												$(this).find(".answerTag").attr("disabled", false);
											}
										});
									}
								} else {
									//显示
									//逻辑类型为"显示" quType=1
									if (thVal != "") {
										//逻辑选项被选中状态，激活状态  显示题
										var hidQuItemBodys = $(".hidFor" + logicId);
										$(".hidFor" + logicId).removeClass("hidFor" + logicId);
										$.each(hidQuItemBodys, function () {
											var thQuItemBodyClass = $(this).attr("class");
											if (thQuItemBodyClass.indexOf("hidFor") < 0) {
												$(this).show();
												$(this).find(".answerTag").attr("disabled", false);
											}
										});
									} else {
										//隐藏题
										var hidQuItemBody = $(".quId[value='" + skQuId + "']").parents(".li_surveyQuItemBody");
										hidQuItemBody.hide();
										hidQuItemBody.addClass("hidFor" + logicId);
										hidQuItemBody.find(".answerTag").attr("disabled", true);
									}
								}
							});
						}
					}
				}

				/**
				 * 保存填空题答案
				 */
				function saveFillblankAnswer(params) {
					console.log("调用 saveFillblankAnswer 函数", params);
					console.log("保存填空")
					// 构建请求数据
					var requestData = {
						belongId: params.id,
						quId: params.quId,
						answer: params.answer,
						belongAnswerId:params.answerRecordId,
					};

					// 调用接口保存答案
					AjaxPostUtil.request({
						url: sysMainMation.surveyBasePath + "writeDwAnFillblank",
						params: requestData,
						type: 'json',
						callback: function (json) {
							// if (json.returnCode === 0) {
							console.log('填空题答案保存成功');
							// 如果需要返回surveyAnswerId给调用方
							if (json.bean && json.bean.surveyAnswerId) {
								return json.bean.surveyAnswerId;
							}
							// } else {
							// 	console.error('填空题答案保存失败：' + json.returnMessage);
							// }
						},
						error: function (xhr, status, error) {
							console.error('保存填空题答案时发生错误：', error);
						}
					});
				}

				/**
				 * 保存单选题答案
				 * @param {Object} params 包含以下参数：
				 *   - id: 问卷ID
				 *   - quId: 题目ID
				 *   - answer: 答案内容(选项ID)
				 *   - answerRecordId: 答卷ID(可选，如果有则传入)
				 */
				function saveRadioAnswer(params) {
					console.log("调用 saveRadioAnswer 函数", params);

					// 构建请求数据
					var requestData = {
						belongId: params.id,       // 问卷ID
						quId: params.quId,         // 题目ID
						quItemId: params.answer,   // 选项ID
						belongAnswerId: params.answerRecordId // 答卷ID(如果有)
					};

					// 如果有答卷ID，则添加到请求数据中
					// if (params.answerRecordId) {
					// 	requestData.belongAnswerId = params.answerRecordId;
					// }

					// 调用接口保存答案
					AjaxPostUtil.request({
						url: sysMainMation.surveyBasePath + "writeDwAnRadio",
						params: requestData,
						type: 'json',
						callback: function (json) {
							console.log('单选题答案保存成功', json);
							// 如果需要返回surveyAnswerId给调用方
							if (json.bean && json.bean.surveyAnswerId) {
								return json.bean.surveyAnswerId;
							}
						},
						error: function (xhr, status, error) {
							console.error('保存单选题答案时发生错误：', error);
						}
					});
				}

				/**
				 * 保存多选题答案
				 * @param {Object} params 包含以下参数：
				 *   - id: 问卷ID
				 *   - quId: 题目ID
				 *   - answers: 选中的答案数组（选项ID）
				 *   - answerRecordId: 答卷ID（可选，如果有则传入）
				 */
				function saveCheckboxAnswer(params) {
					console.log("调用 saveCheckboxAnswer 函数", params);

					// 构建请求数据
					var requestData = {
						belongId: params.id, // 问卷ID
						quId: params.quId, // 题目ID
						quItemIds: params.answers.join(","), // 将选中的答案数组转为字符串
						belongAnswerId: params.answerRecordId // 答卷ID（如果有）
					};

					// // 如果有答卷ID，则添加到请求数据中
					// if (params.answerRecordId) {
					// 	requestData.belongAnswerId = params.answerRecordId;
					// }

					// 调用接口保存答案
					AjaxPostUtil.request({
						url: sysMainMation.surveyBasePath + "writeDwAnCheckbox", // 多选题答案接口
						params: requestData,
						type: 'json',
						callback: function (json) {
							console.log('多选题答案保存成功', json);
							// 如果需要返回surveyAnswerId给调用方
							if (json.bean && json.bean.surveyAnswerId) {
								return json.bean.surveyAnswerId;
							}
						},
						error: function (xhr, status, error) {
							console.error('保存多选题答案时发生错误：', error);
						}
					});
				}

				/**
				 * 保存评分题答案
				 */
				function saveScoreAnswer(params) {
					console.log("调用 saveScoreAnswer 函数", params);

					// 构建请求数据
					var requestData = {
						belongId: params.id, // 问卷ID
						quId: params.quId, // 题目ID
						answer: params.score, // 评分值
						belongAnswerId: params.answerRecordId // 答卷ID（如果有）
					};

					// 调用接口保存答案
					AjaxPostUtil.request({
						url: sysMainMation.surveyBasePath + "writeDwAnScore", // 评分题答案接口
						params: requestData,
						type: 'json',
						callback: function (json) {
							console.log('评分题答案保存成功', json);
							// 如果需要返回surveyAnswerId给调用方
							if (json.bean && json.bean.surveyAnswerId) {
								return json.bean.surveyAnswerId;
							}
						},
						error: function (xhr, status, error) {
							console.error('保存评分题答案时发生错误：', error);
						}
					});
				}

				/**
				 * 保存矩阵单选题答案
				 */
				function saveChenRadioAnswer(params) {
					console.log("调用 saveChenRadioAnswer 函数", params);

					// 构建请求数据
					var requestData = {
						belongId: params.id, // 问卷ID
						quId: params.quId, // 题目ID
						rowId: params.rowId, // 行ID
						columnId: params.columnId, // 列ID
						belongAnswerId: params.answerRecordId // 答卷ID（如果有）
					};

					// 调用接口保存答案
					AjaxPostUtil.request({
						url: sysMainMation.surveyBasePath + "writeDwAnChenRadio", // 矩阵单选题答案接口
						params: requestData,
						type: 'json',
						callback: function (json) {
							console.log('矩阵单选题答案保存成功', json);
							// 如果需要返回surveyAnswerId给调用方
							if (json.bean && json.bean.surveyAnswerId) {
								return json.bean.surveyAnswerId;
							}
						},
						error: function (xhr, status, error) {
							console.error('保存矩阵单选题答案时发生错误：', error);
						}
					});
				}

				/**
				 * 保存矩阵多选题答案
				 */
				function saveChenCheckboxAnswer(params) {
					console.log("调用 saveChenCheckboxAnswer 函数", params);

					// 构建请求数据
					var requestData = {
						belongId: params.id, // 问卷ID
						quId: params.quId, // 题目ID
						rowId: params.rowId, // 行ID
						columnId: params.columnId, // 列ID
						belongAnswerId: params.answerRecordId // 答卷ID（如果有）
					};

					// 调用接口保存答案
					AjaxPostUtil.request({
						url: sysMainMation.surveyBasePath + "writeDwAnChenCheckbox", // 矩阵多选题答案接口
						params: requestData,
						type: 'json',
						callback: function (json) {
							console.log('矩阵多选题答案保存成功', json);
							// 如果需要返回surveyAnswerId给调用方
							if (json.bean && json.bean.surveyAnswerId) {
								return json.bean.surveyAnswerId;
							}
						},
						error: function (xhr, status, error) {
							console.error('保存矩阵多选题答案时发生错误：', error);
						}
					});
				}

				/**
				 * 保存排序题答案
				 */
				function saveOrderAnswer(params) {
					console.log("调用 saveOrderAnswer 函数", params);

					// 构建请求数据
					var requestData = {
						belongId: params.id, // 问卷ID
						quId: params.quId, // 题目ID
						orderItems: JSON.stringify(params.orderItems), // 排序后的选项数组，转为JSON字符串
						belongAnswerId: params.answerRecordId // 答卷ID（如果有）
					};

					// 调用接口保存答案
					AjaxPostUtil.request({
						url: sysMainMation.surveyBasePath + "writeDwAnOrder", // 排序题答案接口
						params: requestData,
						type: 'json',
						callback: function (json) {
							console.log('排序题答案保存成功', json);
							// 如果需要返回surveyAnswerId给调用方
							if (json.bean && json.bean.surveyAnswerId) {
								return json.bean.surveyAnswerId;
							}
						},
						error: function (xhr, status, error) {
							console.error('保存排序题答案时发生错误：', error);
						}
					});
				}

				/**
				 * 保存矩阵评分题答案
				 */
				function saveChenScoreAnswer(params) {
					console.log("调用 saveChenScoreAnswer 函数", params);

					// 构建请求数据
					var requestData = {
						belongId: params.id, // 问卷ID
						quId: params.quId, // 题目ID
						rowId: params.rowId, // 行ID
						columnId: params.columnId, // 列ID
						score: params.score, // 评分值
						belongAnswerId: params.answerRecordId // 答卷ID（如果有）
					};

					// 调用接口保存答案
					AjaxPostUtil.request({
						url: sysMainMation.surveyBasePath + "writeDwAnScore", // 评分题答案接口
						params: requestData,
						type: 'json',
						callback: function (json) {
							console.log('矩阵评分题答案保存成功', json);
							// 如果需要返回surveyAnswerId给调用方
							if (json.bean && json.bean.surveyAnswerId) {
								return json.bean.surveyAnswerId;
							}
						},
						error: function (xhr, status, error) {
							console.error('保存矩阵评分题答案时发生错误：', error);
						}
					});
				}

				/**
				 * 保存矩阵填空题答案
				 */
				function saveChenFbkAnswer(params) {
					console.log("调用 saveChenFbkAnswer 函数", params);

					// 构建请求数据
					var requestData = {
						belongId: params.id, // 问卷ID
						quId: params.quId, // 题目ID
						answers: JSON.stringify(params.answers), // 答案数组，转为JSON字符串
						belongAnswerId: params.answerRecordId // 答卷ID（如果有）
					};

					// 调用接口保存答案
					AjaxPostUtil.request({
						url: sysMainMation.surveyBasePath + "writeDwAnChenFbk", // 矩阵填空题答案接口
						params: requestData,
						type: 'json',
						callback: function (json) {
							console.log('矩阵填空题答案保存成功', json);
							// 如果需要返回surveyAnswerId给调用方
							if (json.bean && json.bean.surveyAnswerId) {
								return json.bean.surveyAnswerId;
							}
						},
						error: function (xhr, status, error) {
							console.error('保存矩阵填空题答案时发生错误：', error);
						}
					});
				}


				function skQuestion(nextQuItemBody, skQuId, logicId, callback) {

					if (nextQuItemBody[0]) {
						var nextQuType = nextQuItemBody.find(".quType").val();
						var nextQuId = nextQuItemBody.find(".quId").val();
						var nextAnswerTag = nextQuItemBody.find(".answerTag");
						//判断跳转类型
						if (skQuId == null) {
							//对于逻辑选项未被选中的情况
						} else if (nextQuItemBody.is(":hidden")) {
							skQuestion(nextQuItemBody.next(), skQuId, logicId, function () {

							});
						} else if (nextQuType != "submitSurveyBtn" && nextQuType != "PAGETAG" && (skQuId === "1" || skQuId === "2" || nextQuId != skQuId)) {
							//对于逻辑项是被选定的情况下
							nextAnswerTag.attr("disabled", true);
							nextQuItemBody.hide();
							nextQuItemBody.addClass("hidFor" + logicId);
							skQuestion(nextQuItemBody.next(), skQuId, logicId, function () { });
						}
					} else {
						callback();
					}
				}

				function resetQuNum() {
					var quCoNums = $(".quCoNum");
					$.each(quCoNums, function (i, item) {
						$(this).html((i + 1) + "、");
					});

				}

				/**********************处理答题进度条************************/

				function answerProgressbar(thObj) {
					// 定义映射表
					var quTypeMap = {
						1: "RADIO",
						2: "CHECKBOX",
						3: "FILLBLANK",
						4: "MULTIFILLBLANK",
						8: "SCORE",
						9: "ORDERQU",
						11: "CHENRADIO",
						12: "CHENFBK",
						13: "CHENCHECKBOX",
						18: "CHENSCORE"
					};

					var quItemBody = thObj.closest(".li_surveyQuItemBody");
					var quTypeInput = quItemBody.find("input.quType"); // 确保使用正确的选择器
					var quTypeIndex = quTypeInput.val(); // 从 input.quType 获取值
					var quType = quTypeMap[quTypeIndex];

					// 根据题型字符串值来处理逻辑
					if (quType === "RADIO") {
						var checks = quItemBody.find("input[type='radio']:checked");
						if (checks[0]) {
							quItemBody.find(".answerTag").val(1);
						} else {
							quItemBody.find(".answerTag").val(0);
						}
					} else if (quType === "CHECKBOX") {
						var checks = quItemBody.find("input[type='checkbox']:checked");
						if (checks[0]) {
							quItemBody.find(".answerTag").val(1);
						} else {
							quItemBody.find(".answerTag").val(0);
						}
					} else if (quType === "FILLBLANK") {
						var thVal = thObj.val();
						if (thVal != "") {
							quItemBody.find(".answerTag").val(1);
						} else {
							quItemBody.find(".answerTag").val(0);
						}
					} else if (quType === "ORDERQU") {
						var orderByLabels = quItemBody.find(".quOrderByLeftUl label");

						if (!orderByLabels[0]) {
							quItemBody.find(".answerTag").val(1);
						} else {
							quItemBody.find(".answerTag").val(0);
						}
					} else if (quType === "SCORE") {
						var quScoreOptionTr = thObj.parents(".quScoreOptionTr");
						var scoreNumInput = quScoreOptionTr.find(".scoreNumInput");
						if (scoreNumInput.val() != "") {
							quScoreOptionTr.find(".answerTag").val(1);
						} else {
							quScoreOptionTr.find(".answerTag").val(0);
						}
					}

					else if (quType === "MULTIFILLBLANK") {
						var mFillblankTableTr = thObj.parents(".mFillblankTableTr");

						// 修改：向上查找到 li_surveyQuItemBody，确保能找到 answerTag
						var quItemBody = thObj.parents(".li_surveyQuItemBody");

						if (thObj.val() != "") {
							// 使用 quItemBody 而非 mFillblankTableTr 来设置 answerTag
							quItemBody.find(".answerTag").val(1);
						} else {
							// 检查同一题目中是否还有其他已填写的填空项
							var otherInputs = quItemBody.find(".dwMFillblankInput").not(thObj);
							var allEmpty = true;

							otherInputs.each(function () {
								if ($(this).val() != "") {
									allEmpty = false;
									return false; // 跳出循环
								}
							});

							if (allEmpty) {
								quItemBody.find(".answerTag").val(0);
							} else {
								quItemBody.find(".answerTag").val(1);
							}
						}
					}

					else if (quType === "CHENRADIO") {
						var dwQuCoChenRowTr = thObj.parents(".dwQuCoChenRowTr");
						var quItemBody = thObj.parents(".li_surveyQuItemBody");
						dwQuCoChenRowTr.find(".answerTag").val(1);

						if (thObj.val() != "") {
							// 使用 quItemBody 而非 dwQuCoChenRowTr 来设置 answerTag
							quItemBody.find(".answerTag").val(1);
						} else {
							// 检查同一题目中是否还有其他已填写的填空项
							var otherInputs = quItemBody.find(".dwChenInputTemp").not(thObj);
							var allEmpty = true;

							otherInputs.each(function () {
								if ($(this).val() != "") {
									allEmpty = false;
									return false; // 跳出循环
								}
							});

							if (allEmpty) {
								quItemBody.find(".answerTag").val(0);
							} else {
								quItemBody.find(".answerTag").val(1);
							}
						}

					} else if (quType === "CHENCHECKBOX") {
						var dwQuCoChenRowTr = thObj.parents(".dwQuCoChenRowTr");
						var checks = dwQuCoChenRowTr.find("input[type='checkbox']:checked");
						if (checks[0]) {
							dwQuCoChenRowTr.find(".answerTag").val(1);
						} else {
							dwQuCoChenRowTr.find(".answerTag").val(0);
						}
					} else if (quType === "CHENSCORE") {
						var dwQuScoreOptionItemContent = thObj.parents(".dwQuScoreOptionItemContent");
						var quItemBody = thObj.parents(".li_surveyQuItemBody");

						if (thObj.val() != "0") {
							quItemBody.find(".answerTag").val(1);
						} else {
							quItemBody.find(".answerTag").val(0);
						}
					} else if (quType === "CHENFBK") {
						var dwQuChenFbkOptionItemContent = thObj.parents(".dwQuChenFbkOptionItemContent");
						if (thObj.val() != "") {
							dwQuChenFbkOptionItemContent.find(".answerTag").val(1);
						} else {
							dwQuChenFbkOptionItemContent.find(".answerTag").val(0);
						}
					}

					// 计算答题进度 - 修改为使用题目容器计数
					var totalQuSize = $(".li_surveyQuItemBody").size() - 1; // 使用题目容器统计总题数
					var answerTag1 = $(".answerTag[value='1']:enabled");

					// 统计已回答的题目数
					var answerQuSize = 0;
					$(".li_surveyQuItemBody").each(function () {
						if ($(this).find(".answerTag[value='1']:enabled").length > 0) {
							answerQuSize++;
						}
					});

					var newValue = parseInt(answerQuSize / totalQuSize * 100);
					$("#resultProgressRoot .progress-label").text("完成度：" + newValue + "%");
					$("#resultProgress").progressbar("option", "value", newValue);
				}

				// 矩阵填空题输入框change事件
				$(".dwChenMFillblankInput").off("change").on("change", function() {
					var thObj = $(this);
					var quItemBody = thObj.parents(".li_surveyQuItemBody");
					var dwChenInputTemp = thObj.parent().find(".dwChenInputTemp").val();
					var rowId = dwChenInputTemp.split(":")[0];
					var columnId = dwChenInputTemp.split(":")[1];
					var answer = thObj.val();

					// 收集所有填空答案
					var answers = [{
						rowId: rowId,
						columnId: columnId,
						answer: answer
					}];

					// 调用保存函数
					saveChenFbkAnswer({
						id: getUrlParam("rowId"), // 问卷ID
						quId: quItemBody.find(".quId").val(), // 题目ID
						answers: answers, // 答案数组
						answerRecordId: answerRecordId // 答卷ID（如果有）
					});

					// 更新进度条
					answerProgressbar(thObj);
					// 运行逻辑
					runlogic(thObj);
					validateCheck(quItemBody, false);
				});
			});
		});
	</script>
</body>

</html>